package cn.com.huzo.webapp.controller.master;

import huzofw.common.web.controller.BaseFormController;
import cn.com.huzo.model.entities.master.OrderLossEntity;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import cn.com.huzo.service.master.OrderLossManager;

/**
 * 订货损耗控制器
 *
 * @author 吴旭
 */
@Controller
public class OrderLossController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "OrderLossManager")
    private OrderLossManager _manager;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到订货损耗一览画面
     *
     * @return
     */
    @RequestMapping("master/order_loss/list.html")
    public ModelAndView redirectListWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("master.order_loss.list.def");
        return view;
    }

    /**
     * 弹出订货损耗选择画面
     * <p>
     * @return
     */
    @RequestMapping("master/order_loss/choice.html")
    public ModelAndView redirectLossRatePopupWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("popup.master.order_loss.choice.def");
        return view;
    }

    /**
     * 转到订货损耗在线维护画面
     * <p>
     * @return
     */
    @RequestMapping("master/order_loss/online/edit.html")
    public ModelAndView redirectLossRateOnlineEditWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("popup.master.order_loss.online_edit.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得订货损耗分页数据。
     * <p>
     * @param criterion 检索条件
     * @return 分页数据
     * @throws Exception
     */
    @RequestMapping(value = "master/order_loss/fetchForPage.html",
            method = RequestMethod.POST,
            produces = {"application/xml", "application/json"})
    public @ResponseBody
    Map<String, Object> fetchForPage(@RequestBody Map<String, Object> criterion) throws Exception {
        return _manager.fetchForPage(criterion);
    }

    /**
     * 批量保存。
     *
     * @param criterion 要处理的订货损耗数据
     * @return
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/order_loss/save.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> batchUpdate(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager.batchUpdate(criterion);
    }

    /**
     * 在线编辑。
     *
     * @param instance 要增加的的订货损耗数据
     * @return 增加的数据主键
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/order_loss/single/save.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Long saveOne(@RequestBody final OrderLossEntity instance) throws Exception {
        return _manager.insert(instance);
    }

    /**
     * 删除。
     *
     * @param criterion 要删除的数据
     * @return 返回删除后的数据
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/order_loss/delete.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> delete(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager.delete(criterion);
    }
    // </editor-fold>
}
